const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const schema = new Schema({
  machine: {type: String, required: true, default: '', index: true},
  service: {type: String, required: true, default: ''},
  type: {type: String, required: true, enum: ['in', 'out'], default: 'in', index: true},
  method: {type: String, required: true, default: ''},
  agent: {type: String, required: true, default: ''},
  ip: {type: String, required: true, default: ''},
  requestId: {type: String, required: true, default: '', index: true},
  url: {type: String, required: true, default: ''},
  interface: {type: String, required: true, default: '', index: true},
  userId: {type: String, required: true, default: '', index: true},
  orderId: {type: String, required: true, default: '', index: true},
  execTime: {type: Number, required: true, default: 0},
  request: {type: Object, required: true, default: {}},
  response: {type: Object, required: true, default: {}},
  extend: {type: Object, required: true, default: {}},
  responseTime: {type: Number, required: true, default: 0},
  requestTime: {type: Number, required: true, default: 0, index: true},
});

schema.set('timestamps', true); // createAt, updatedAt -> UTC
schema.set('minimize', false);

module.exports = schema;
